#include "WOH_BoundingVolume.h"

CBoundingVolume::CBoundingVolume(void)
{
}

CBoundingVolume::~CBoundingVolume(void)
{
}

bool CBoundingVolume::Create( const D3DXVECTOR3* pVertices,int nVertices,DWORD dwStride )
{
	D3DXComputeBoundingBox(pVertices,nVertices,dwStride,&m_BoundingBox.vMin,&m_BoundingBox.vMax);
	D3DXComputeBoundingSphere(pVertices,nVertices,dwStride,&m_BoundingSphere.vCenter,&m_BoundingSphere.fRadius);
	
	LOG::Instance()->OutputSuccess("BoundingVolume Create Successful");
	return true;
}

bool CBoundingVolume::Create( LPD3DXMESH pMesh )
{
	BYTE* pVertices;
	pMesh->LockVertexBuffer(0,(void**)&pVertices);

	D3DXComputeBoundingBox((D3DXVECTOR3*)pVertices,pMesh->GetNumVertices(),
		D3DXGetFVFVertexSize(pMesh->GetFVF()),&m_BoundingBox.vMin,&m_BoundingBox.vMax);
	D3DXComputeBoundingSphere((D3DXVECTOR3*)pVertices,pMesh->GetNumVertices(),
		D3DXGetFVFVertexSize(pMesh->GetFVF()),&m_BoundingSphere.vCenter,&m_BoundingSphere.fRadius);


	pMesh->UnlockVertexBuffer();
	LOG::Instance()->OutputSuccess("BoundingVolume Create Successful");
	return true;

}
